/*
 * @Author: wuzhouhai wzh200x@126.com
 * @Date: 2024-08-01 15:47:46
 * @LastEditors: wuzhouhai wzh200x@126.com
 * @LastEditTime: 2024-08-08 17:10:43
 * @FilePath: \dwys_web\assets\script\ui\shop\Shop.ts
 * @Description: 
 */
import { _decorator, Component, Node } from 'cc';
import { CCComp } from '../../../../extensions/oops-plugin-framework/assets/module/common/CCComp';
import { Label } from 'cc';
import { Button } from 'cc';
import { EventTouch } from 'cc';
import { oops } from '../../../../extensions/oops-plugin-framework/assets/core/Oops';
import { GameEvent } from '../../common/event/GameEvent';
import * as proto from "../../phoenix/protoc/ts/proto_app.js";
const { ccclass, property } = _decorator;

@ccclass('Shop')
export class Shop extends CCComp {

    @property(Label)
    labelName:Label | undefined;

    @property(Label)
    labelActive:Label | undefined;

    shop : proto.Iroom_info |undefined = undefined;

    reset(): void {
        throw new Error('Method not implemented.');
    }

    start() {
        oops.message.on(GameEvent.UpdateRoomShow, this.onUpdateRoom, this)
    }

    protected onDestroy(): void {
        oops.message.off(GameEvent.UpdateRoomShow, this.onUpdateRoom, this)
    }

    update(deltaTime: number) {
        
    }

    InitShop(shop:proto.Iroom_info){
        this.shop = shop;
        this.labelName!.string = this.shop.name!;
        this.SetActive(this.shop.active!);
    }

    onUpdateRoom(e: string, room: proto.Iroom_info){
        if(this.shop && this.shop!.roomId == room.roomId){
            this.shop!.active = room.active;
            this.SetActive(room.active!);
        }
    }

    SetActive(active:number){
        this.labelActive!.node.active = active != 1;
    }

    onClickShop(e: EventTouch, s: any){
        if (this.shop == undefined) return;
        oops.message.dispatchEvent(GameEvent.RequestGetRoomPmtInfo, this.shop?.roomId, this.shop!.active == 1);
        oops.message.dispatchEvent(GameEvent.SelectRoom, this.shop!);
        if (this.shop!.active == 0){
            oops.message.dispatchEvent(GameEvent.AddGameMsgInfo, "[" + this.shop!.name + "]店铺未激活");
        }
    }
}


